

<title>增值税普票</title>
  
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>增值税普票</cite></a>
    </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-vatgeneral-formlist">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">发票号码</label>
                <div class="layui-input-block">
                    <input type="text" name="invoiceNumber" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">开票日期</label>
                <div class="layui-inline" id="ID-laydate-rangeLinked">
                    <div class="layui-input-inline">
                        <input type="text" autocomplete="off" id="ID-laydate-start-date-vatgeneral" name="issueDateStart" class="layui-input" placeholder="开始日期">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline">
                        <input type="text" autocomplete="off" id="ID-laydate-end-date-vatgeneral" name="issueDateEnd" class="layui-input" placeholder="结束日期">
                    </div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">上传时间</label>
                <div class="layui-inline" id="ID-laydate-rangeLinked-vatgeneral-uploadTime">
                    <div class="layui-input-inline">
                        <input type="text" autocomplete="off" id="ID-laydate-start-date-vatgeneral-list-uploadtime" name="uploadTimeStart" class="layui-input" placeholder="开始时间">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline">
                        <input type="text" autocomplete="off" id="ID-laydate-end-date-vatgeneral-list-uploadtime" name="uploadTimeEnd" class="layui-input" placeholder="结束时间">
                    </div>
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-queryinvoice-vatgeneral-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 查询
                </button>
                <button class="layui-btn layuiadmin-btn-useradmin" lay-on="clear">
                    <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i> 清空
                </button>
            </div>
        </div>
    </div>
    
    <div class="layui-card-body">
        <table id="LAY-queryinvoice-vatgeneral-manage" lay-filter="LAY-queryinvoice-vatgeneral-manage"></table>
        <script type="text/html" id="table-useradmin-webuser">
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
            <!-- 这里同样支持 laytpl 语法，如： -->
            {{#  if(d.isEnabled == 'Y'){ }}
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="disable"><i class="layui-icon layui-icon-disabled"></i>禁用</a>
            {{#  }else{ }}
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="enable"><i class="layui-icon layui-icon-ok-circle"></i>启用</a>
            {{#  } }}
        </script>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="export">导出Excel</button>
            </div>
        </script>
    </div>
  </div>
</div>

<script>
    layui.use('vatgeneral', layui.factory('vatgeneral')).use(['admin', 'table', 'util'], function(){
  var $ = layui.$
      , admin = layui.admin
      , setter = layui.setter
      ,view = layui.view
      , table = layui.table
      , laydate = layui.laydate
      , util = layui.util
      ,form = layui.form;
  
        form.render(null, 'layadmin-vatgeneral-formlist');

        //处理自定义事件
        util.on({
            clear: function () {
                console.log(this); // 当前触发事件的 DOM 元素

                $(':input[name=invoiceNumber]').val('');
                $('#ID-laydate-start-date-vatgeneral').val('');
                $('#ID-laydate-end-date-vatgeneral').val('');
                $('#ID-laydate-start-date-vatgeneral-list-uploadtime').val('');
                $('#ID-laydate-end-date-vatgeneral-list-uploadtime').val('');
                //form.render($('#ID-select-myinvoice-billtype'));

                //执行重载
                table.reload('LAY-queryinvoice-vatgeneral-manage', {
                    where: {}
                });
            }
        });

    // 日期范围 - 左右面板联动选择模式
    laydate.render({
        elem: '#ID-laydate-rangeLinked',
        range: ['#ID-laydate-start-date-vatgeneral', '#ID-laydate-end-date-vatgeneral'],
        rangeLinked: true // 开启日期范围选择时的区间联动标注模式 ---  2.8+ 新增
    });

    //上传时间
    laydate.render({
        elem: '#ID-laydate-rangeLinked-vatgeneral-uploadTime',
        range: ['#ID-laydate-start-date-vatgeneral-list-uploadtime', '#ID-laydate-end-date-vatgeneral-list-uploadtime'],
        rangeLinked: true,
        type: 'datetime',
        fullPanel: true
    });
  
  //开启搜索
  form.on('submit(LAY-queryinvoice-vatgeneral-search)', function (data) {
      var field = data.field;

      //添加单据类型
      field.billType = "1";
    
    //执行重载
    table.reload('LAY-queryinvoice-vatgeneral-manage', {
      where: field
    });
  });

  //事件
  var active = {
    batchdel: function(){
      var checkStatus = table.checkStatus('LAY-queryinvoice-vatgeneral-manage')
      ,checkData = checkStatus.data; //得到选中的数据

      if(checkData.length === 0){
        return layer.msg('请选择数据');
      }
      
      layer.prompt({
        formType: 1
        ,title: '敏感操作，请验证口令'
      }, function(value, index){
        layer.close(index);
        
        layer.confirm('确定删除吗？', function(index) {
          
          //执行 Ajax 后重载
          /*
          admin.req({
            url: 'xxx'
            //,……
          });
          */
          table.reload('LAY-queryinvoice-vatgeneral-manage');
          layer.msg('已删除');
        });
      });
    }
    ,add: function(){
      admin.popup({
        title: '添加用户'
        ,area: ['500px', '450px']
        ,id: 'LAY-popup-user-add'
        ,success: function(layero, index){
          view(this.id).render('user/user/userform').done(function(){
            form.render(null, 'layuiadmin-form-useradmin');
            
            //开启提交
              form.on('submit(LAY-user-front-submit)', function (data) {
              var field = data.field; //获取提交的字段

                //提交 Ajax 成功后，关闭当前弹层并重载表格
                $.ajax({
                    url: setter.baseConfig.apiHost + '/api/user/add' //实际使用请改成服务端真实接口
                    , type: 'post'
                    , contentType: "application/json"
                    , data: JSON.stringify(field)
                    , beforeSend: function (xhr) {
                        xhr.setRequestHeader("Authorization", 'Bearer ' + layui.data(setter.tableName)[setter.request.tokenName]);
                    }
                    , success: function (res) {
                        if (res.errorCode != '00000') {
                            layer.msg(res.errorMessage, {
                                offset: '15px'
                                , icon: 2
                                , time: 3000
                            });

                            return false;
                        }

                        //登入成功的提示与跳转
                        layer.msg('添加成功', {
                            offset: '15px'
                            , icon: 1
                            , time: 3000
                        });

                        layui.table.reload('LAY-queryinvoice-vatgeneral-manage'); //重载表格
                        layer.close(index); //执行关闭
                    }
                }); 
            });
          });
        }
      });
    }
  };
  
  $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});
</script>